/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Resource")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Resource.findAll", query = "SELECT r FROM Resource r"),
    @NamedQuery(name = "Resource.findByName", query = "SELECT r FROM Resource r WHERE r.name = :name")})
public class Resource implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "resource1")
    private Collection<ProductionCost> productionCostCollection;
    @Column(name = "init_amount")
    private Integer initAmount;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "resource1")
    private Collection<Tribute> tributeCollection;

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "name")
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "resource1")
    private Collection<Storage> storageCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "resource1")
    private Collection<Cost> costCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "resource1")
    private Collection<Production> productionCollection;

    public Resource() {
    }

    public Resource(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<Storage> getStorageCollection() {
        return storageCollection;
    }

    public void setStorageCollection(Collection<Storage> storageCollection) {
        this.storageCollection = storageCollection;
    }

    @XmlTransient
    public Collection<Cost> getCostCollection() {
        return costCollection;
    }

    public void setCostCollection(Collection<Cost> costCollection) {
        this.costCollection = costCollection;
    }

    @XmlTransient
    public Collection<Production> getProductionCollection() {
        return productionCollection;
    }

    public void setProductionCollection(Collection<Production> productionCollection) {
        this.productionCollection = productionCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (name != null ? name.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Resource)) {
            return false;
        }
        Resource other = (Resource) object;
        if ((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Resource[ name=" + name + " ]";
    }

    public Integer getInitAmount() {
        return initAmount;
    }

    public void setInitAmount(Integer initAmount) {
        this.initAmount = initAmount;
    }

    @XmlTransient
    public Collection<Tribute> getTributeCollection() {
        return tributeCollection;
    }

    public void setTributeCollection(Collection<Tribute> tributeCollection) {
        this.tributeCollection = tributeCollection;
    }

    @XmlTransient
    public Collection<ProductionCost> getProductionCostCollection() {
        return productionCostCollection;
    }

    public void setProductionCostCollection(Collection<ProductionCost> productionCostCollection) {
        this.productionCostCollection = productionCostCollection;
    }
}
